package com.mofum.cloud.controller;

import com.mofum.cloud.core.error.ins.InstructionAlgorithmException;
import com.mofum.cloud.core.error.ins.InstructionNotFoundException;
import com.mofum.cloud.core.handler.impl.StaticInstructionsHandlerPoolImpl;
import com.mofum.cloud.core.model.Algorithm;
import com.mofum.cloud.support.cpu.m6502.ADC;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;

/**
 * HelloWorld控制器
 *
 * @author yumi@omuao.com
 */
@RestController
@RequestMapping("/hello")
public class HelloWorldController {

    @GetMapping("/execute")
    public String execute() throws InstructionNotFoundException, InstructionAlgorithmException {
        StaticInstructionsHandlerPoolImpl pool = new StaticInstructionsHandlerPoolImpl();
        pool.registerIns(new ADC());
        Algorithm a = pool.findInstructionById(BigInteger.ZERO).getAlgorithm();
        long nanoTime = System.nanoTime();
        a.execute();
        System.out.println("纳秒:" + (System.nanoTime() - nanoTime));
        return "SUCCESS";
    }
}
